﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using TjZheng.Core.Mvc;
using TjZheng.Framework;

namespace TjZheng.JiaLi.Process
{
    public abstract class TicketProcessHandler : JiaLiProcessHandler
    {
        protected override InvokeResult CheckBeforeCatch(JiaLiContext objJiaLiContext)
        {
            InvokeResult objInvokeResult = new InvokeResult();
            TicketContext objTicketContext = objJiaLiContext as TicketContext;
            if (objTicketContext == null)
            {
                objInvokeResult.ResultCode = "TicketContextNull";
                objInvokeResult.ResultMessage = "对不起，票据上下文为空";
                return objInvokeResult;
            }

            if (objTicketContext.ValidTicketInfo.Version != this.GetType().ToString())
            {
                objInvokeResult.ResultCode = "VersionNotMatch";
                objInvokeResult.ResultMessage = "对不起，你当前的运行版本不一致";
                return objInvokeResult;
            }

            XmlDocument objXmlDocument1 = TicketInfo.TicketPath.CreateXmlDocument();
            XmlDocument objXmlDocument2 = objTicketContext.ActiveXml;

            if (object.Equals(objXmlDocument1, objXmlDocument2))
            {
                if (objTicketContext.ExpireTime.IsLessEqualCurrent())
                {
                    objInvokeResult.ResultCode = "TicketExpired";
                    objInvokeResult.ResultMessage = "对不起，您的产品已过期，请您与管理员联系";
                }
            }
            else
            {
                objInvokeResult.ResultCode = "ActiveXmlChange";
                objInvokeResult.ResultMessage = "对不起，激活文件被修改，请重新运行程序";
            }
            return objInvokeResult;
        }

        [TicketValid]
        public override ProcessResult StartCatchImages(JiaLiContext objJiaLiContext)
        {
            return base.StartCatchImages(objJiaLiContext);
        }
    }
}
